﻿<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta name="referrer" content="no-referrer" />
    <!--<script>setTimeout(function () { location.reload() }, 10 * 60 * 1000); //指定60秒刷新一次</script>-->
    <title>bilibili fans barrage system</title>
    <link rel="shortcut icon" href="favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" type="text/css" href="/static/css/bootstrap.min.css" media="screen" />
    <link rel="stylesheet" type="text/css" href="/static/css/style.css" />
    <link rel="stylesheet" type="text/css" href="/static/css/barrager.css">
    <link rel="stylesheet" type="text/css" href="/static/pick-a-color/css/pick-a-color-1.2.3.min.css">
    <link type="text/css" rel="stylesheet" href="/static/syntaxhighlighter/styles/shCoreDefault.css" />
    <style type="text/css">
        html,
        body {
            height: 100%;
            width: 100%
        }
    </style>

</head>

<body onload="add()">

    <div style="background:url(static/img/bililogo3.jpg);background-size:cover; height:100%; width: 100%;">



    </div>



    <!-- JS dependencies -->
    <script type="text/javascript" src="static/js/jquery-1.9.1.min.js"></script>
    <script type="text/javascript" src="static/js/bootstrap.min.js"></script>
    <script type="text/javascript" src="static/js/tinycolor-0.9.15.min.js"></script>
    <script type="text/javascript" src="static/dist/js/jquery.barrager.min.js"></script>
    <script type="text/javascript" src="static/syntaxhighlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="static/syntaxhighlighter/scripts/shBrushJScript.js"></script>
    <script type="text/javascript" src="static/syntaxhighlighter/scripts/shBrushPhp.js"></script>
    <script type="text/javascript" src="static/pick-a-color/js/pick-a-color-1.2.3.min.js"></script>
    <script type="text/javascript">

        String.prototype.format = function (args) {
            var result = this;
            if (arguments.length < 1) {
                return result;
            }
            var data = arguments;
            if (arguments.length == 1 && typeof (args) == "object") {
                data = args;
            }
            for (var key in data) {
                var value = data[key];
                if (undefined != value) {
                    result = result.replace("{" + key + "}", value);
                }
            }
            return result;
        }
        var barrager_code =
            'var item={\n' +
            "   img:'{img}', //图片 \n" +
            "   info:'{info}', //文字 \n" +
            "   href:'{href}', //链接 \n" +
            "   close:{close}, //显示关闭按钮 \n" +
            "   speed:{speed}, //延迟,单位秒,默认6 \n" +
            "   bottom:{bottom}, //距离底部高度,单位px,默认随机 \n" +
            "   color:'{color}', //颜色,默认白色 \n" +
            "   old_ie_color:'{old_ie_color}', //ie低版兼容色,不能与网页背景相同,默认黑色 \n" +
            " }\n" +
            "$('body').barrager(item);"
            ;

        $(function () {

            SyntaxHighlighter.all();
            $(".pick-a-color").pickAColor();
            var item = { 'img': 'static/img/l1.jpg', 'href': 'https://icomgx.cn', 'info': '粉丝弹幕系统启动成功...' };


            $('body').barrager(item);



            //每条弹幕发送间隔
            var looper_time = 3 * 1000;
            //是否首次执行
            var run_once = true;
            // do_barrager();

            function do_barrager() {
                if (run_once) {
                    //如果是首次执行,则设置一个定时器,并且把首次执行置为false
                    looper = setInterval(do_barrager, looper_time);
                    run_once = false;
                }
                //获取
                $.getJSON('server.php?mode=1', function (data) {
                    //是否有数据
                    if (data.info) {

                        $('body').barrager(data);
                    }

                });
            }

            function barrager() {



            }







        });

        function run() {

            var info = $('input[name=info]').val();
            (info == '') ? info = '请填写弹幕文字' : info = info;
            var href = $('input[name=href]').val();
            var speed = parseInt($('input[name=speed]').val());
            var bottom = parseInt($('input[name=bottom]').val());
            var code = barrager_code;
            if ($('input:radio[name=bottomradio]:checked').val() == 0) {
                var window_height = $(window).height() - 150;
                bottom = Math.floor(Math.random() * window_height + 40);
                code = code.replace("   bottom:{bottom}, //距离底部高度,单位px,默认随机 \n", '');

            }

            var img = $('input:radio[name=img]:checked').val();

            if (img == 'none') {

                code = code.replace("   img:'{img}', //图片 \n", '');
            }




            var item = {
                'img': 'static/img/' + img,
                'info': info,
                'href': href,
                'close': true,
                'speed': speed,
                'bottom': bottom,
                'color': '#' + $('input[name=color').val(),
                'old_ie_color': '#' + $('input[name=color').val()



            };

            if (!$('input[name=close]').is(':checked')) {


                item.close = false;


            }


            code = code.format(item);
            console.log(code);
            $('#barrager-code').val(code);
            eval(code);


        }

        function clear_barrage() {

            $.fn.barrager.removeAll();
        }





        function run_example() {

            var example_item = { 'img': 'static/img/heisenberg.png', 'info': 'Hello world!' };
            $('body').barrager(example_item);
            return false;

        }

        function add() {
            var looper_time = 0.5 * 1000;
            //是否首次执行
            var run_once = true;
            do_barrager();

            function do_barrager() {
                if (run_once) {
                    //如果是首次执行,则设置一个定时器,并且把首次执行置为false
                    looper = setInterval(do_barrager, looper_time);
                    run_once = false;
                }
                //获取
                $.getJSON('/api/barrage/display', function (data) {
                    //是否有数据
                    if (data.info) {

                        $('body').barrager(data);
                    }

                });
            }
        }





    </script>
</body>

</html>